#ifndef	__CXX_VIEWS_GRPH_BITMAP_IMPL_H__
#define	__CXX_VIEWS_GRPH_BITMAP_IMPL_H__

#include "bitmap.h"
#include "grphoal.h"

namespace visgrph
{

class canvas;

class bitmap_impl
{
	friend class canvas;
public:
	bitmap_impl()
		: m_refcnt(1), m_width(0), m_height(0),
		m_stride(0), m_flags(0), m_target(NULL)
	{
	}

	~bitmap_impl();
	bool create(uint width, uint height, uint stride);
	bool attach(void* buf, uint width, uint height, uint stride);

	int addref(void);
	int release(void);

public:
	uint width(void) { return m_width; }
	uint height(void) { return m_height; }
	uint stride(void) { return m_stride; }
	uint buffer(void) { return (uint)m_target; }

private:

	// release the target buffer if necessary
	// this will not destroy the object
	void reset_buffer(void* buf);

private:

	enum bitmap_impl_flags
	{
		bmp_imp_flag_attached_buf = 1,
	};
	// sync object for bitmap
	grphoal::syncobject m_syncobj;

	int	 m_refcnt;
	uint m_width;
	uint m_height;
	uint m_stride;
	uint m_flags;
	void *m_target;
};

};	// namespace visgrph

#endif	// __CXX_VIEWS_GRPH_CANVAS_H__
/* EOF */

